﻿using System;
using System.Collections.Generic;
using System.Linq;
using HiStaff.Base;
using HiStaff.Control;
using HiStaff.Domain.IN;
using HiStaff.Domain.Sys;
using HiStaff.Util;
using HiStaff.Dal;
using Janus.Windows.GridEX;
using System.Data;
using System.Windows.Forms;
namespace HiStaff.iInsurance
{
    public partial class DeclareInsurance :FormBase
    {
        public DeclareInsurance()
        {
            InitializeComponent();

        }
        protected override bool FormLoad()
        {
            base.CreateCommandBar(CommandBarManager.ActionCommand.Save,
                    CommandBarManager.ActionCommand.Delete,
                    CommandBarManager.ActionCommand.Separator,
                    CommandBarManager.ActionCommand.Exit);
            return base.FormLoad();
        }
        protected override void SetToolStripButtonBar(CommandBarManager.ActionCommand cmd)
        {
            
        }
        protected override void SetStatusInputControl(System.Windows.Forms.Control container)
        {
            
        }
        private void BindData()
        {
            try
            {
                var lstEmployee = OracleHelper.ExcuteSelectMultiObject<IN_CHANGE>("PRS_DECLARE_CHANGE", new SEARCH { ORGID = trvOrg.OrgId, CHGFROM = dtFromdate.Value, CHGTO = dtTodate.Value, INSCHGROUP = ConvertHelper.ToDecimal(cbbGroup.SelectedValue) });
                grdMain.DataSource = lstEmployee;
                grdMain.Refresh();
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
            }
        }

        private void trvOrg_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                BindData();
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
            }
        }

        protected override bool SaveButtonClick()
        {
            try
            {
                foreach (var item in grdMain.GetCheckedRows())
                {
                    if (item.RowType == RowType.Record)
                    {
                        var obj = (IN_CHANGE)item.DataRow;
                        obj.INSCHANGETYPE =ConvertHelper.ToDecimal (cbbEnchtype.SelectedValue) ;
                        obj.PERIODREPORT = cdPeriodDate.Value;
                        OracleHelper.ExcuteNonQuery("PRI_DECLARE_CHAGE", obj);
                    }
                }

                BindData();
                MessageBox.Show(GetMessageById(Constant.MSG_TRANSACTION_SUCCESSFUL), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
                return false;
            }
        }

    }
}
